# import os
# import time
#
# from PIL import Image
#
#
# def list_files_in_subdirs(directory):
#     """ 列出指定目录及其所有子目录中的文件 """
#     my_list = []
#     for root, dirs, files in os.walk(directory):
#         for file in files:
#             my_list.append(os.path.join(root, file))
#     return my_list
#
#
# def list_directories(path):
#     """返回指定路径下的所有目录"""
#     return [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))]
#
#
# if __name__ == '__main__':
#     '''
#     地图合并
#     '''
#     print('开始')
#     timestamp = int(time.time())
#     directories = list_directories("D:\\2")
#     for cccc in directories:
#         temp_dir = "D:\\2\\" + cccc
#         # 单张图片宽度
#         dd_width = 0
#         # 单张图片高度
#         dd_height = 0
#         # 横向有多少张图片
#         x_number = 0
#         # 竖向有多少张图片
#         y_number = 0
#         my_list = list_files_in_subdirs(temp_dir)
#         for element in my_list:
#             aa = element.split("\\")[-1].replace(".png", "").split("_")
#             if x_number < int(aa[0]):
#                 x_number = int(aa[0])
#             if y_number < int(aa[1]):
#                 y_number = int(aa[1])
#         x_number += 1
#         y_number += 1
#         for element in my_list:
#             image1 = Image.open(element)
#             if dd_width < image1.width:
#                 dd_width = image1.width
#             if dd_height < image1.height:
#                 dd_height = image1.height
#         new_image = Image.new('RGBA', (dd_width * x_number, dd_height * y_number))
#         for element in my_list:
#             image1 = Image.open(element)
#             aa = element.split("\\")[-1].replace(".png", "").split("_")
#             new_image.paste(image1, (dd_width * int(aa[0]), dd_height * int(aa[1])))
#         new_image.save("D:\\3\\" + cccc + ".png")
#     endTime = int(time.time())
#     print(str(endTime - timestamp))
#     print('结束')
